package cn.school.controller.stu.evaluation;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.stu.evaluation.entity.StuEvaPlan;
import cn.school.stu.evaluation.service.StuEvaPlanService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author: lx
 * @date: 2023/5/25 8:51
 * @description:
 */
@RestController
@Api(tags = "StuEvaPlanController => 学生考评方案控制器")
@RequestMapping("stu/evaluation/plan")
public class StuEvaPlanController {

    @Autowired
    StuEvaPlanService stuEvaPlanService;

    @PostMapping("/createStuEvaPlan")
    public CommonResult createStuEvaPlan(@RequestBody StuEvaPlan stuEvaPlan){
        int num = stuEvaPlanService.createStuEvaPlan(stuEvaPlan);
        if(num > 0){
            return CommonResult.success();
        }else {
            return CommonResult.failed();
        }
    }

    @PostMapping("/findStuEvaPlanPageList")
    public CommonResult<CommonPage<StuEvaPlan>> findStuEvaPlanPageList(@RequestBody Map<String, Object> queryParam){
        IPage<StuEvaPlan> page = stuEvaPlanService.findStuEvaPlanPageList(queryParam);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @GetMapping("/findStuEvaPlanById/{id}")
    public CommonResult findStuEvaPlanById(@PathVariable("id") Long id){
        StuEvaPlan stuEvaPlan = stuEvaPlanService.findStuEvaPlanById(id);
        return CommonResult.success(stuEvaPlan);
    }

    @GetMapping("/deleteStuEvaPlanById/{id}")
    public CommonResult deleteStuEvaPlanById(@PathVariable("id") Long id){
        int num = stuEvaPlanService.deleteStuEvaPlanById(id);
        if(num > 0){
            return CommonResult.success();
        }else {
            return CommonResult.failed();
        }
    }
}
